test: Adopt TUnit TestGroup and modernize test codebase#335
Conversation
- Add NetEvolve.Extensions.TUnit and annotate all test classes with [TestGroup] for improved organization and filtering. - Remove legacy region markers and redundant test double/helper code. - Update test code to use C# 12 features (e.g., collection expressions, array initializers). - Apply minor doc comment and namespace formatting improvements. - Simplify and modernize test assertions and resource management. - Clean up static using directives and type aliases. - Overall, enhance maintainability, readability, and test discoverability.
WalkthroughThis pull request systematically adds TUnit test group categorization across the test suite by introducing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #335 +/- ##
=======================================
Coverage 71.21% 71.21%
=======================================
Files 105 105
Lines 3787 3787
Branches 338 338
=======================================
Hits 2697 2697
Misses 1016 1016
Partials 74 74 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
tests/NetEvolve.Pulse.Tests.Unit/HttpCorrelation/HttpCorrelationExtensionsTests.cs (1)
14-14: Consider addingSuppressMessageattribute for consistency.Other test classes in this PR (e.g.,
HttpCorrelationEventInterceptorTests,HttpCorrelationRequestInterceptorTests) include a[SuppressMessage("IDisposableAnalyzers.Correctness", "CA2000:Dispose objects before losing scope", ...)]attribute. This class also createsServiceProviderinstances without explicit disposal (lines 29, 43, 112, 128). Adding the same suppression would maintain consistency and silence potential analyzer warnings.♻️ Suggested addition
using TUnit.Core; +[SuppressMessage( + "IDisposableAnalyzers.Correctness", + "CA2000:Dispose objects before losing scope", + Justification = "ServiceProvider instances are short-lived within test methods" +)] [TestGroup("HttpCorrelation")] public sealed class HttpCorrelationExtensionsTestsYou'll also need to add the using directive if not already present via global usings:
using System.Diagnostics.CodeAnalysis;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/NetEvolve.Pulse.Tests.Unit/HttpCorrelation/HttpCorrelationExtensionsTests.cs` at line 14, Add a SuppressMessage attribute to the HttpCorrelationExtensionsTests class to match other tests: annotate the class HttpCorrelationExtensionsTests with [SuppressMessage("IDisposableAnalyzers.Correctness", "CA2000:Dispose objects before losing scope", Justification = "Test creates ServiceProvider instances that are not disposed in test harness")] and ensure the System.Diagnostics.CodeAnalysis using is present (or available via global usings) so the attribute compiles; target the same analysis category and rule used in HttpCorrelationEventInterceptorTests and HttpCorrelationRequestInterceptorTests for consistency.tests/NetEvolve.Pulse.Tests.Unit/RabbitMQ/RabbitMqExtensionsTests.cs (1)
1-1: Consider whether the UTF-8 BOM is necessary.The UTF-8 Byte Order Mark (BOM) character (
) before the namespace declaration is generally unnecessary in modern C# projects. While it doesn't break compilation, it can cause issues with some tools and may appear as unexpected characters in certain editors.If this is being applied consistently across the codebase for a specific tooling requirement, it's fine. Otherwise, standard UTF-8 without BOM is the typical convention.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/NetEvolve.Pulse.Tests.Unit/RabbitMQ/RabbitMqExtensionsTests.cs` at line 1, Remove the leading UTF-8 BOM character before the namespace declaration in the file containing namespace NetEvolve.Pulse.Tests.Unit.RabbitMQ; open that test file and delete the invisible BOM character at the top so the file is saved as plain UTF-8 (no BOM), then re-save and commit the change to avoid tooling/editor issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/NetEvolve.Pulse/Interceptors/LoggingMessages.cs`:
- Line 1: The file contains a UTF-8 Byte Order Mark (BOM) at the start which
should be removed; open src/NetEvolve.Pulse/Interceptors/LoggingMessages.cs
(namespace NetEvolve.Pulse.Interceptors / file LoggingMessages.cs) and re-save
the file as UTF-8 without BOM (e.g., using your editor’s “Save with Encoding” →
UTF-8 without BOM or run a script to strip the BOM), then ensure other affected
C# files are saved the same way and commit the changes so diffs/tooling no
longer include the BOM.
---
Nitpick comments:
In
`@tests/NetEvolve.Pulse.Tests.Unit/HttpCorrelation/HttpCorrelationExtensionsTests.cs`:
- Line 14: Add a SuppressMessage attribute to the HttpCorrelationExtensionsTests
class to match other tests: annotate the class HttpCorrelationExtensionsTests
with [SuppressMessage("IDisposableAnalyzers.Correctness", "CA2000:Dispose
objects before losing scope", Justification = "Test creates ServiceProvider
instances that are not disposed in test harness")] and ensure the
System.Diagnostics.CodeAnalysis using is present (or available via global
usings) so the attribute compiles; target the same analysis category and rule
used in HttpCorrelationEventInterceptorTests and
HttpCorrelationRequestInterceptorTests for consistency.
In `@tests/NetEvolve.Pulse.Tests.Unit/RabbitMQ/RabbitMqExtensionsTests.cs`:
- Line 1: Remove the leading UTF-8 BOM character before the namespace
declaration in the file containing namespace
NetEvolve.Pulse.Tests.Unit.RabbitMQ; open that test file and delete the
invisible BOM character at the top so the file is saved as plain UTF-8 (no BOM),
then re-save and commit the change to avoid tooling/editor issues.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c51dbc14-50a9-41e0-a075-5b7bb8a9eff8
📒 Files selected for processing (78)
src/NetEvolve.Pulse/Dispatchers/PrioritizedEventDispatcher.cssrc/NetEvolve.Pulse/Interceptors/LoggingMessages.cstests/NetEvolve.Pulse.Tests.Unit/ActivityMetricsExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/AspNetCore/EndpointRouteBuilderExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/AssemblyScanningExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/AzureServiceBus/AzureServiceBusExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/AzureServiceBus/AzureServiceBusMessageTransportTests.cstests/NetEvolve.Pulse.Tests.Unit/Dapr/DaprExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/Dapr/DaprMessageTransportTests.cstests/NetEvolve.Pulse.Tests.Unit/Dispatchers/ParallelEventDispatcherTests.cstests/NetEvolve.Pulse.Tests.Unit/Dispatchers/PrioritizedEventDispatcherTests.cstests/NetEvolve.Pulse.Tests.Unit/Dispatchers/RateLimitedEventDispatcherTests.cstests/NetEvolve.Pulse.Tests.Unit/Dispatchers/SequentialEventDispatcherTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/EntityFrameworkEventOutboxTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/EntityFrameworkExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/EntityFrameworkOutboxManagementTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/EntityFrameworkOutboxRepositoryTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/EntityFrameworkOutboxTransactionScopeTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/ModelBuilderExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/OutboxMessageConfigurationFactoryTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/OutboxMessageConfigurationMetadataTests.cstests/NetEvolve.Pulse.Tests.Unit/EntityFramework/TypeValueConverterTests.cstests/NetEvolve.Pulse.Tests.Unit/EventDispatcherExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/FluentValidation/FluentValidationExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/FluentValidation/Interceptors/FluentValidationRequestInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/HttpCorrelation/HttpCorrelationExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/HttpCorrelation/Interceptors/HttpCorrelationEventInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/HttpCorrelation/Interceptors/HttpCorrelationRequestInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/HttpCorrelation/Interceptors/HttpCorrelationStreamQueryInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/IdempotencyExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/ActivityAndMetricsEventInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/ActivityAndMetricsRequestInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/ActivityAndMetricsStreamQueryInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/DistributedCacheQueryInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/IdempotencyCommandInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/LoggingEventInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/LoggingInterceptorOptionsValidatorTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/LoggingRequestInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Interceptors/TimeoutRequestInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Internals/MediatorBuilderTests.cstests/NetEvolve.Pulse.Tests.Unit/Internals/PulseMediatorTests.cstests/NetEvolve.Pulse.Tests.Unit/Kafka/KafkaExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/Kafka/KafkaMessageTransportTests.cstests/NetEvolve.Pulse.Tests.Unit/LoggingExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/Outbox/ExponentialBackoffTests.cstests/NetEvolve.Pulse.Tests.Unit/Outbox/InMemoryMessageTransportTests.cstests/NetEvolve.Pulse.Tests.Unit/Outbox/OutboxEventHandlerTests.cstests/NetEvolve.Pulse.Tests.Unit/Outbox/OutboxExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/Outbox/OutboxProcessorHostedServiceTests.cstests/NetEvolve.Pulse.Tests.Unit/Outbox/OutboxStatisticsTests.cstests/NetEvolve.Pulse.Tests.Unit/Polly/Interceptors/PollyEventInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Polly/Interceptors/PollyRequestInterceptorTests.cstests/NetEvolve.Pulse.Tests.Unit/Polly/PollyExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/PostgreSql/PostgreSqlEventOutboxTests.cstests/NetEvolve.Pulse.Tests.Unit/PostgreSql/PostgreSqlExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/PostgreSql/PostgreSqlOutboxManagementTests.cstests/NetEvolve.Pulse.Tests.Unit/PostgreSql/PostgreSqlOutboxOptionsExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/PostgreSql/PostgreSqlOutboxRepositoryTests.cstests/NetEvolve.Pulse.Tests.Unit/PostgreSql/PostgreSqlOutboxTransactionScopeTests.cstests/NetEvolve.Pulse.Tests.Unit/QueryCachingExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/RabbitMQ/RabbitMqExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/RabbitMQ/RabbitMqMessageTransportTests.cstests/NetEvolve.Pulse.Tests.Unit/SQLite/SQLiteEventOutboxTests.cstests/NetEvolve.Pulse.Tests.Unit/SQLite/SQLiteExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/SQLite/SQLiteOutboxManagementDatabaseTests.cstests/NetEvolve.Pulse.Tests.Unit/SQLite/SQLiteOutboxManagementTests.cstests/NetEvolve.Pulse.Tests.Unit/SQLite/SQLiteOutboxOptionsExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/SQLite/SQLiteOutboxRepositoryDatabaseTests.cstests/NetEvolve.Pulse.Tests.Unit/SQLite/SQLiteOutboxRepositoryTests.cstests/NetEvolve.Pulse.Tests.Unit/SQLite/SQLiteOutboxTransactionScopeTests.cstests/NetEvolve.Pulse.Tests.Unit/ServiceCollectionExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/SqlServer/SqlServerEventOutboxTests.cstests/NetEvolve.Pulse.Tests.Unit/SqlServer/SqlServerExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/SqlServer/SqlServerOutboxManagementTests.cstests/NetEvolve.Pulse.Tests.Unit/SqlServer/SqlServerOutboxOptionsExtensionsTests.cstests/NetEvolve.Pulse.Tests.Unit/SqlServer/SqlServerOutboxRepositoryTests.cstests/NetEvolve.Pulse.Tests.Unit/SqlServer/SqlServerOutboxTransactionScopeTests.cs
| @@ -1,4 +1,4 @@ | |||
| namespace NetEvolve.Pulse.Interceptors; | |||
| namespace NetEvolve.Pulse.Interceptors; | |||
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Check for UTF-8 BOM in C# source files
# Find all C# files with BOM (EF BB BF byte sequence)
echo "=== C# files with UTF-8 BOM ==="
fd -e cs -x bash -c 'if [ "$(head -c 3 "{}" | od -An -tx1 | tr -d " ")" = "efbbbf" ]; then echo "{}"; fi'
echo ""
echo "=== Total count ==="
fd -e cs -x bash -c 'if [ "$(head -c 3 "{}" | od -An -tx1 | tr -d " ")" = "efbbbf" ]; then echo "1"; fi' | wc -lRepository: dailydevops/pulse
Length of output: 16944
🏁 Script executed:
#!/bin/bash
# Check for UTF-8 BOM in C# files using Python
python3 << 'EOF'
import os
import glob
# Find all C# files
csharp_files = glob.glob('**/*.cs', recursive=True)
# Check for BOM (first 3 bytes: EF BB BF)
bom_files = []
target_file = 'src/NetEvolve.Pulse/Interceptors/LoggingMessages.cs'
for filepath in csharp_files:
try:
with open(filepath, 'rb') as f:
first_bytes = f.read(3)
if first_bytes == b'\xef\xbb\xbf':
bom_files.append(filepath)
except:
pass
print("=== C# files with UTF-8 BOM ===")
if bom_files:
for f in sorted(bom_files):
print(f)
else:
print("(none found)")
print(f"\n=== Total count: {len(bom_files)} ===")
# Specifically check the target file
print(f"\n=== Checking target file: {target_file} ===")
if os.path.exists(target_file):
with open(target_file, 'rb') as f:
first_bytes = f.read(3)
has_bom = first_bytes == b'\xef\xbb\xbf'
print(f"Has BOM: {has_bom}")
print(f"First bytes (hex): {first_bytes.hex()}")
print(f"First 50 chars: {first_bytes + open(target_file, 'rb').read(50)[:47]}")
else:
print(f"File not found")
EOFRepository: dailydevops/pulse
Length of output: 11349
Remove UTF-8 BOM from C# files across the codebase.
UTF-8 Byte Order Marks (BOMs) have been added to 159 C# files including this one. BOMs are unnecessary for C# source files and cause issues with tooling, version control diffs, and cross-platform compatibility. Remove the BOM from all affected files.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/NetEvolve.Pulse/Interceptors/LoggingMessages.cs` at line 1, The file
contains a UTF-8 Byte Order Mark (BOM) at the start which should be removed;
open src/NetEvolve.Pulse/Interceptors/LoggingMessages.cs (namespace
NetEvolve.Pulse.Interceptors / file LoggingMessages.cs) and re-save the file as
UTF-8 without BOM (e.g., using your editor’s “Save with Encoding” → UTF-8
without BOM or run a script to strip the BOM), then ensure other affected C#
files are saved the same way and commit the changes so diffs/tooling no longer
include the BOM.
Summary by CodeRabbit
Tests
Documentation